package com.linfeng.component.common.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class CustomExceptionSerializer extends StdSerializer<CustomException> {

    protected CustomExceptionSerializer() {
        super(CustomException.class);
    }

    @Override
    public void serialize(CustomException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeNumberField("code", e.getCode());
        jsonGenerator.writeStringField("message", e.getMessage());
        jsonGenerator.writeEndObject();
    }
}
